import {
  loginHyRequest
} from "./index";

export const wxLogin = function () {
  return new Promise((resolve, reject) => {
    wx.login({
      timeout: 1000,
      success: (res) => {
        resolve(res)
      },
      fail: (err) => {
        console.log(err);
        reject(err)
      }
    })
  })
}

export const codeToToken = function (data) {
  return loginHyRequest.post("/login", data)
}

export const checkToken = function (header) {
  return loginHyRequest.post("/auth", {}, header)
}

export const checkSession = function () {
  return new Promise((resolve, reject) => {
    wx.checkSession({
      success: (res) => {
        resolve(true)
      },
      fail: (err) => {
        resolve(false)
      },
    })
  })
}

export const getUserInfo = function () {
  return new Promise((resolve, reject) => {
    wx.getUserProfile({
      desc: 'desc',
      success(res) {
        resolve(res)
      },
      fail(err) {
        reject(err)
      }
    })
  })
}